//package com.bestcem.xm.deliver.grpc.service;
//
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.bestcem.xm.deliver.entity.DeliverAgainDeliverTask;
//import com.bestcem.xm.deliver.entity.DeliverAgainDeliverType;
//import com.bestcem.xm.deliver.grpc.client.QdesGrpcClient;
//import com.bestcem.xm.deliver.grpc.client.UserGrpcClient;
//import com.bestcem.xm.deliver.grpc.client.dto.OrgInfoDto;
//import com.bestcem.xm.deliver.grpc.v1.services.BpDeliverTicketServiceGrpc;
//import com.bestcem.xm.deliver.grpc.v1.services.CreateTicketAgainDeliverRequest;
//import com.bestcem.xm.deliver.grpc.v1.services.CreateTicketAgainDeliverResponse;
//import com.bestcem.xm.deliver.mapper.DeliverAgainDeliverRecordMapper;
//import com.bestcem.xm.deliver.mapper.DeliverAgainDeliverTaskMapper;
//import com.bestcem.xm.deliver.mapper.DeliverAgainDeliverTypeMapper;
//import com.bestcem.xm.deliver.mapper.DeliverDeliverMapper;
//import com.bestcem.xm.deliver.mapper.DeliverSmsBalanceMapper;
//import com.bestcem.xm.qdes.grpc.v1.services.Project;
//import com.bestcem.xm.qdes.grpc.v1.services.QStruct;
//import io.grpc.stub.StreamObserver;
//import lombok.NonNull;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import net.devh.boot.grpc.server.service.GrpcService;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.transaction.annotation.Transactional;
//import zhongyan.xm.base.v1.Base;
//
//import java.util.List;
//
//@GrpcService
//@Slf4j
//@RequiredArgsConstructor
//public class BpDeliverTicketGrpcService extends BpDeliverTicketServiceGrpc.BpDeliverTicketServiceImplBase {
//    private static final Base.Status SUCCESS_STATUS = Base.Status.newBuilder().setCode(Base.Code.OK).build();
//    private static final Base.Status FAIL_STATUS = Base.Status.newBuilder().setCode(Base.Code.ERROR).build();
//
//    private @NonNull DeliverDeliverMapper deliverDeliverMapper;
//    private @NonNull DeliverAgainDeliverTaskMapper deliverAgainDeliverTaskMapper;
//    private @NonNull DeliverAgainDeliverRecordMapper deliverAgainDeliverRecordMapper;
//    private @NonNull DeliverAgainDeliverTypeMapper deliverAgainDeliverTypeMapper;
//    private @NonNull DeliverSmsBalanceMapper deliverSmsBalanceMapper;
//
//    private @NonNull UserGrpcClient userGrpcClient;
//    private @NonNull QdesGrpcClient qdesGrpcClient;
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void createTicketAgainDeliver(CreateTicketAgainDeliverRequest request,
//        StreamObserver<CreateTicketAgainDeliverResponse> responseObserver) {
//
//    }
//
//
//    private String createAgainDeliver(CreateTicketAgainDeliverRequest request) {
//        // 创建二次投放记录，同时进行短信投放
//        String againDeliverTaskId = request.getAgainDeliverTaskId();
//        String deliverId = request.getDeliverId();
//        String ticketId = request.getTicketId();
//        long seq = request.getSeq();
//        String memberId = request.getMemberId();
//        String orgId = request.getOrgId();
//        String surveyId = request.getSurveyId();
//
//        log.info("开始创建二次投放");
//        log.info("开始创建二次投放,参数, request = {}", JSONObject.toJSONString(request));
//        LambdaQueryWrapper<DeliverAgainDeliverType> typeWrapper = new LambdaQueryWrapper<>();
//        typeWrapper.eq(DeliverAgainDeliverType::getAgainDeliverTaskId, againDeliverTaskId)
//            .eq(DeliverAgainDeliverType::getDeliverId, deliverId);
//        List<DeliverAgainDeliverType> deliverTypes = deliverAgainDeliverTypeMapper.selectList(typeWrapper);
//        String sign = "【倍市得CEM】";
//        OrgInfoDto org = userGrpcClient.getOrganization(orgId);
//        String skin = org.getSkin();
//        String systematicName = "倍市得CEM";
//        if (StringUtils.isNotEmpty(skin)) {
//            JSONObject skinJs = JSONObject.parseObject(skin);
//            if (skinJs.get("status") != null) {
//                systematicName = skinJs.getString("name");
//            }
//            if (StringUtils.isEmpty(systematicName)) {
//                systematicName = "倍市得CEM";
//            }
//        }
//        systematicName = systematicName.length() > 15 ? systematicName.substring(0, 15) : systematicName;
//        log.info("获取的短信签名 = {}", sign);
//        DeliverAgainDeliverTask deliverAgainDeliverTask = deliverAgainDeliverTaskMapper.selectById(againDeliverTaskId);
//        Project project = qdesGrpcClient.getProject(deliverAgainDeliverTask.getDeliverProjectId());
//        QStruct qStruct = qdesGrpcClient.getQStruct(project.getStructId());
//
//        // todo 后续需要再实现，目前python也有许多todo的
//        return "";
//    }
//
//}
